package com.jyw.business.obstacles.service.impl;

import java.util.List;

import com.jyw.business.obstacles.domain.ObsOrderProcess;
import com.jyw.business.obstacles.domain.dto.wechat.EvaluateOrderDto;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.utils.FileUtils;
import org.springframework.stereotype.Service;
import com.jyw.business.obstacles.mapper.ObsOrderEvaluateMapper;
import com.jyw.business.obstacles.domain.ObsOrderEvaluate;
import com.jyw.business.obstacles.service.IObsOrderEvaluateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 工单评价Service业务层处理
 *
 * @author ZhangCheng
 * @date 2023-08-10
 */
@Service
public class ObsOrderEvaluateServiceImpl extends ServiceImpl<ObsOrderEvaluateMapper, ObsOrderEvaluate> implements IObsOrderEvaluateService {
    @Resource
    private ObsOrderEvaluateMapper obsOrderEvaluateMapper;

    /**
     * 查询工单评价
     *
     * @param id 工单评价主键
     * @return 工单评价
     */
    @Override
    public ObsOrderEvaluate selectObsOrderEvaluateById(Long id) {
        return obsOrderEvaluateMapper.selectObsOrderEvaluateById(id);
    }

    /**
     * 查询工单评价列表
     *
     * @param obsOrderEvaluate 工单评价
     * @return 工单评价
     */
    @Override
    public List<ObsOrderEvaluate> selectObsOrderEvaluateList(ObsOrderEvaluate obsOrderEvaluate) {
        return obsOrderEvaluateMapper.selectObsOrderEvaluateList(obsOrderEvaluate);
    }

    /**
     * 新增工单评价
     *
     * @param obsOrderEvaluate 工单评价
     * @return 结果
     */
    @Override
    public int insertObsOrderEvaluate(ObsOrderEvaluate obsOrderEvaluate) {
        obsOrderEvaluate.setCreateTime(DateUtils.getNowDate());
        return obsOrderEvaluateMapper.insert(obsOrderEvaluate);
    }

    /**
     * 修改工单评价
     *
     * @param obsOrderEvaluate 工单评价
     * @return 结果
     */
    @Override
    public int updateObsOrderEvaluate(ObsOrderEvaluate obsOrderEvaluate) {
        obsOrderEvaluate.setUpdateTime(DateUtils.getNowDate());
        return obsOrderEvaluateMapper.updateObsOrderEvaluate(obsOrderEvaluate);
    }

    /**
     * 批量删除工单评价
     *
     * @param ids 需要删除的工单评价主键
     * @return 结果
     */
    @Override
    public int deleteObsOrderEvaluateByIds(Long[] ids) {
        return obsOrderEvaluateMapper.deleteObsOrderEvaluateByIds(ids);
    }

    /**
     * 删除工单评价信息
     *
     * @param id 工单评价主键
     * @return 结果
     */
    @Override
    public int deleteObsOrderEvaluateById(Long id) {
        return obsOrderEvaluateMapper.deleteObsOrderEvaluateById(id);
    }

    @Override
    public void evaluateOrder(EvaluateOrderDto dto) {
        ObsOrderEvaluate evaluate = new ObsOrderEvaluate();
        BeanUtils.copyProperties(dto, evaluate);
        evaluate.setCreateUser(SecurityUtils.getUserId());
        evaluate.setCreateTime(DateUtils.getNowDate());
        evaluate.setEnclosure(FileUtils.fileToId(dto.getEnclosureList()));
        this.save(evaluate);
    }
}
